package org.cangku.controller;

import org.cangku.dao.MemberTypeDao;
import org.cangku.entity.Membertype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/membertype")
public class MemberTypeController {

    @Autowired
    private MemberTypeDao memberTypeDao;

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(int offset,int limit){
        Map<String,Object> map = new HashMap<String, Object>();

        map.put("rows",memberTypeDao.query(offset,limit));
        map.put("total",memberTypeDao.count());

        return map;
    }
    @RequestMapping("/insert")
    @ResponseBody
    public Map<String,Object> insert(Membertype membertype){
        Map<String,Object> map = new HashMap<String, Object>();

        memberTypeDao.insert(membertype);

        map.put("rows",memberTypeDao.query(0,5));
        map.put("total",memberTypeDao.count());

        return map;
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(Membertype membertype){
        Map<String,Object> map = new HashMap<String, Object>();

        memberTypeDao.update(membertype);

        map.put("rows",memberTypeDao.query(0,5));
        map.put("total",memberTypeDao.count());

        return map;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Map<String,Object> delete(int id){
        Map<String,Object> map = new HashMap<String, Object>();

        memberTypeDao.delete(id);

        map.put("rows",memberTypeDao.query(0,5));
        map.put("total",memberTypeDao.count());

        return map;
    }
}
